//
//  ProfilesViewController.m
//  Rockval
//
//  Created by TuanNT on 4/29/14.
//  Copyright (c) 2014 TNL. All rights reserved.
//

#import "ProfilesViewController.h"

@interface ProfilesViewController ()
@property (nonatomic, weak) IBOutlet UIImageView *avatarImageView;
@property (nonatomic, weak) IBOutlet UILabel *userName;
@property (nonatomic, weak) IBOutlet UILabel *email;
@end

@implementation ProfilesViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
		// Custom initialization
	}
	return self;
}

- (void)viewDidLoad {
	[super viewDidLoad];
	// Do any additional setup after loading the view.
	[self setUpView];
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	[self.navigationController setToolbarHidden:YES animated:NO];
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}

/*
   #pragma mark - Navigation

   // In a storyboard-based application, you will often want to do a little preparation before navigation
   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
   {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
   }
 */

//================================ METHODS ================================
#pragma mark -
#pragma mark METHODS

- (void)setUpView {
	Account *account = [DataManager sharedInstance].account;

	DLogError(@"account = %@", account);

	self.avatarImageView.layer.cornerRadius = self.avatarImageView.bounds.size.width / 2;
	[self.avatarImageView setImageWithURL:[NSURL URLWithString:account.image]
	          usingActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

	NSString *userName = [NSString stringWithFormat:@"%@ %@", account.firstname ? :@"", account.lastname ? :@""];
	[self.userName setText:userName];
    [self.userName setTextAlignment:NSTextAlignmentLeft];
    NSString* contentString = account.email;
	int tempCount = 1;
    if (account.telephone.length > 0) {
        contentString  = [NSString stringWithFormat:@"%@\n%@",contentString,account.telephone];
        tempCount++;
    }
    /*data hardcode*/
    account.streetAddress = @"test";
    account.country = @"84";
    account.city = @"HN";
    account.postcode = @"12345";
    /*end*/
        /*street*/
    contentString = [NSString stringWithFormat:@"%@\n%@",contentString,account.streetAddress != nil ? (NSString*)account.streetAddress:@""];
        /*country*/
        contentString = [NSString stringWithFormat:@"%@\n%@",contentString,[[DataManager getFullContries] objectForKey:account.country] != nil ? (NSString*)account.country:@""];
        /*city*/
        contentString = [NSString stringWithFormat:@"%@\n%@",contentString,account.city != nil ? (NSString*)account.city:@""];
        /*postcode*/
        contentString = [NSString stringWithFormat:@"%@\n%@",contentString,account.postcode != nil ? (NSString*)account.postcode:@""];
    [self.email setText:contentString];
    [self.email setFrame:CGRectMake(self.email.frame.origin.x, self.email.frame.origin.y, self.email.frame.size.width, 145)];
    //[self.email setBackgroundColor:[UIColor redColor]];
    self.email.lineBreakMode = NSLineBreakByWordWrapping;
    [self.email setTextAlignment:NSTextAlignmentLeft];
    self.email.numberOfLines = 0;
    
    
}

@end
